#! c:\\Perl\\bin\\perl.exe w

use strict;
use ADN::LIBRARY::IP::Ip;
use ADN::LIBRARY::SNMP::Discovery;
use ADN::SERVER::ParsePID;
use ADN::SERVER::StartUP;
use ADN::LOG::Log;
use ADN::LANG::Lang;

my $ip = $ARGV[0];
my $Srep = $ARGV[1];
my $param = $ARGV[2];
my $log = ADN::LOG::Log->new();
my %lang = ADN::LANG::Lang->new()->recherche();

main();
exit 0;

sub main {

  my ( $result, $verifip, $discovery, $nbr );
  my ( @tab, @prm, @i_p, @proc );

  @tab = split /\%\!\%\*\%\~\%/smx, $param;
  $nbr = scalar @tab;
  print "NBR : $nbr\n";

  for ( my $i = 0; $i < $nbr; $i++ ) {
    @prm = split /\@\#\@\*\@\~\@/smx, $tab[$i];
  }

  $nbr = scalar @prm;
  print "NBR PRM : $nbr\n";

  if ($nbr != 2) {
    print 'Erreur ARG !!!';
    exit 0;
  }
  if (($prm[0] =~ /^stop$/smx) && ($prm[1] =~ /^[0-9\w]+$/smx)) {
  	$log->Log( $lang{mess1} . $prm[1], 1, 5 );
		@proc = ADN::SERVER::StartUP->_proc();
		ADN::SERVER::ParsePID->new()->start(Cmd => 'kill',
		         														Proc => \@proc,
		         														Name => 'LanceRecherche',
		         														Groupe => 'IRechercheSonde',
		         														ID => $prm[1]);
		return;
	} else {
	
  	print "ARG : $prm[0]/$prm[1]";

  	$verifip = ADN::LIBRARY::IP::Ip->new($prm[0].'/'.$prm[1]);
		$discovery = ADN::LIBRARY::SNMP::Discovery->new();
  	@i_p = $verifip->start();
		$result = $discovery->start(\@i_p, $ip, $Srep);
  	return;
  }
}
